package com.svpino.netflix;

import java.util.HashMap;
import java.util.Map.Entry;

public abstract class AbstractQueryable<T> implements Queryable<T> {

	private final ProxyImpl connection;
	private HashMap<String, String> parameters;

	public AbstractQueryable(ProxyImpl connection) {
		this.connection = connection;
		this.parameters = new HashMap<String, String>();
		this.parameters.put("v", "2.0");
	}

	protected HashMap<String, String> getParameters() {
		return this.parameters;
	}

	protected String getUrl(String baseUrl) {
		String url = baseUrl;
		for (Entry<String, String> parameter : getParameters().entrySet()) {
			url += url.contains("?") ? "&" : "?";
			url += parameter.getKey() + "=" + parameter.getValue();
		}

		return url;
	}

	protected ProxyImpl getConnection() {
		return this.connection;
	}

}
